# /usr/bin/env python3.6
# -*- encoding: utf-8 -*-
"""
@File    : cinema_address_api.py
@Time    : 2020/2/7 0007 13:39
@Author  : zhangbing
@Email   : 18829172841@163.com
@Software: PyCharm
"""
from flask import g
from flask_restful import Resource, reqparse, abort, fields, marshal

from App.apis.api_constant import HTTP_CREATE_OK
from App.apis.cinema_admin.utils import required_cinemaaddress_permission, login_cinema_required
from App.models.cinema_admin.cinema_address_model import CinemaAddress
from App.models.cinema_admin.permission_constant import PERMISSION_WRITE

'''
此接口主要用于添加和修改影院信息
'''

parse = reqparse.RequestParser()

parse.add_argument("name", type=str, required=True, help="请输入影院名称！")
parse.add_argument("city", type=str, required=True, help="请输入城市地址称！")
parse.add_argument("district", type=str, required=True, help="请输入影院名称！")
parse.add_argument("address", type=str, required=True, help="请输入影院详细地址！")
parse.add_argument("phone", type=str, required=True, help="请输入影院联系人电话！")

cinema_address_fields = {
    "name": fields.String,
    "city": fields.String,
    "district": fields.String,
    "address": fields.String,
    "phone": fields.String,
}


class CinemaAddressResource(Resource):
    @login_cinema_required
    def get(self):
        pass

    @required_cinemaaddress_permission(PERMISSION_WRITE)
    def post(self):
        args = parse.parse_args()
        name = args.get("name")
        city = args.get("city")
        district = args.get("district")
        address = args.get("address")
        phone = args.get("phone")
        cinema_address = CinemaAddress()
        cinema_address.c_user_id = g.user.id
        cinema_address.name = name
        cinema_address.city = city
        cinema_address.phone = phone
        cinema_address.district = district
        cinema_address.address = address
        if not cinema_address.save():
            abort(400, msg="cinema  can't  save")
        data = {
            "status": HTTP_CREATE_OK,
            "msg": "cinema  create ok",
            "data": marshal(cinema_address, cinema_address_fields)
        }
        return data


class CinemaAddresResource(Resource):
    def get(self, address_id):
        pass

    def put(self, address_id):
        pass

    def patch(self, address_id):
        pass

    def delete(self, address_id):
        pass


if __name__ == "__main__":
    pass
